home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / ShellPanel / NISave.m < prev    next >
Text File  |  1995-06-12  |  2KB  |  72 lines

  1. /* File: NISave.m - (Interactive) Unix shell version of NISavePanel
  2.  *
  3.  * By: Christopher Lane (lane@sumex-aim.stanford.edu)
  4.  *
  5.  * Date: 10 November 1992
  6.  *
  7.  * Copyright: 1991 & 1992 by The Leland Stanford Junior University.
  8.  * This program may be distributed without restriction for non-commercial use.
  9.  */
  10.  
  11. #import <stdlib.h>
  12. #import <getopt.h>
  13. #import <strings.h>
  14. #import <sys/param.h>
  15. #import <nikit/NISavePanel.h>
  16. #import <appkit/Application.h>
  17.  
  18. #define USAGE "usage: %s [-d directory] [-t title] [-p prompt] [-f directory]\n"
  19. #define EXIT_USAGE (2)
  20. #define SEPARATOR "/"
  21.  
  22. const char *fullPath(const char *parent, const char *name)
  23. {
  24.     static char buffer[MAXPATHLEN];
  25.     
  26.     if(parent == NULL) return name;
  27.     
  28.     if(strcmp(strcpy(buffer, parent), SEPARATOR) != 0) (void) strcat(buffer, SEPARATOR);
  29.     
  30.     return strcat(buffer, name);
  31. }
  32.  
  33. void main(int argc, char *argv[])
  34. {
  35.     const char *title = NULL, *prompt = NULL, *path = NULL, *string = "";
  36.     int option, status = EXIT_SUCCESS;
  37.     
  38.     NXApp = [Application new];
  39.     
  40.     while ((option = getopt(argc, argv, "d:t:p:f:")) != EOF)
  41.         switch (option) {
  42.         case 'd': path = optarg; break;
  43.         case 't': title = optarg; break;
  44.         case 'p': prompt = optarg; break;
  45.         case 'f': string = optarg; break;
  46.         default : status = EXIT_USAGE;
  47.         }
  48.     if (optind < argc) status = EXIT_USAGE;    
  49.     
  50.     if (status == EXIT_USAGE) (void) fprintf(stderr, USAGE, [NXApp appName]);
  51.     else {
  52.         int flags, context = [NXApp activateSelf:YES];
  53.         NISavePanel *panel = [NISavePanel new];
  54.     
  55.         if (prompt != NULL) [panel setListTitle:(char *) prompt];
  56.         if (title != NULL) [panel setPanelTitle:(char *) title];
  57.         if (path != NULL) [panel setStartingDomainPath:path];
  58.     
  59.         if ((flags = [panel runModalWithString:(char *) string]) == NX_OKTAG)
  60.             (void) puts(fullPath([panel domain], [panel directory]));
  61.         else status = flags;
  62.  
  63.         [panel free];
  64.         
  65.         if (context) (void) [NXApp activate:context];
  66.         }
  67.     
  68.     [NXApp free];
  69.     
  70.     exit(status);
  71. }
  72.